package com.ssy.lingxi.settle.accounts.controller;

import com.ssy.lingxi.common.controller.BaseController;
import com.ssy.lingxi.common.response.PageData;
import com.ssy.lingxi.common.response.Wrapper;
import com.ssy.lingxi.settle.accounts.model.vo.request.*;
import com.ssy.lingxi.settle.accounts.model.vo.response.ToBeConfirmReconciliationVO;
import com.ssy.lingxi.settle.accounts.model.vo.response.TobeApplyAmountListVO;
import com.ssy.lingxi.settle.accounts.service.IBusinessReconciliationService;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.validation.Valid;

/**
 * @menu 平台结算管理-业务对账-协同-采购方
 * @author Saske
 * @date 2021/12/6
 **/
@RestController
@RequestMapping("/settle/accounts/business/reconciliation/teamwork")
public class BusinessReconciliationTeamworkController extends BaseController {

    @Resource
    private IBusinessReconciliationService reconciliationService;

    /**
     * 分页查询对账单列表-采购方
     * @author Saske
     * @return 查询结果
     */
    @RequestMapping(value = "/buyer/reconciliation/list",method = RequestMethod.GET)
    public Wrapper<PageData<ToBeConfirmReconciliationVO>> pageBuyerReconciliation( HttpServletRequest request ,ReconciliationListVO reconciliationListVO){
        return reconciliationService.pageBuyerReconciliation(getSysUser(request),reconciliationListVO);
    }

    /**
     * 对账单列表导出
     * @author Saske
     */
    @RequestMapping(value = "/buyer/reconciliation/export", method = RequestMethod.GET)
    public void exportReconciliation(HttpServletResponse response, ReconciliationListVO reconciliationListVO, String token) {
        reconciliationService.exportBuyerReconciliation(response,reconciliationListVO,token);
    }

    /**
     * 待确认对账单列表-付款方为当前登录会员（会员角色为服务消费者）
     * @author Saske
     */
    @RequestMapping(value = "/confirm/reconciliation/list",method = RequestMethod.GET)
    public Wrapper<PageData<ToBeConfirmReconciliationVO>> confirmReconciliationList( HttpServletRequest request,@Valid  ToBeSaveReconciliationListVO toBeSaveReconciliationListVO){
        return reconciliationService.pageConfirmReconciliation(getSysUser(request),toBeSaveReconciliationListVO);
    }

    /**
     * 确认对账单
     * @author Saske
     */
    @RequestMapping(value = "/confirm/reconciliation",method = RequestMethod.POST)
    public Wrapper<Long> confirmReconciliation( HttpServletRequest request,@Valid @RequestBody ReconciliationRejectConfirmVo reconciliationConfirmVo){
        return reconciliationService.confirmReconciliation(getSysUser(request),reconciliationConfirmVo);
    }

    /**
     * 待请款列表
     * @author Saske
     */
    @RequestMapping(value = "/tobe/applyamount/list",method = RequestMethod.GET)
    public Wrapper<PageData<TobeApplyAmountListVO>> toBeApplyAmountList( HttpServletRequest request,@Valid ToBeSaveReconciliationListVO toBeSaveReconciliationListVO){
        return reconciliationService.pageToBeApplyAmountReconciliation(getSysUser(request),toBeSaveReconciliationListVO);
    }

    /**
     * 请款提交，生成请款单数据
     * @author Saske
     */
    @RequestMapping(value = "/generate/apply/mount",method = RequestMethod.POST)
    public Wrapper<ApplyAmountSaveVO> generateReconciliation(HttpServletRequest request, @RequestBody ReconciliationApplyVO applyVO){
        return reconciliationService.generateApplyAmount(getSysUser(request),applyVO);
    }
}
